package com.cskaoyan.controller.vx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.po.wxPo.MarketUser;
import com.cskaoyan.bean.vo.HomeAboutVo;
import com.cskaoyan.bean.vo.vxVo.WxHomeIndexPageVO;
import com.cskaoyan.bean.vo.vxVo.WxHomePageVO;
import com.cskaoyan.bean.vo.vxVo.WxIndexVO;
import com.cskaoyan.config.shiro.MallToken;
import com.cskaoyan.service.OrderService;
import com.cskaoyan.service.vx.WxHomeService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx")
public class WxHomeController {
    @Autowired
    OrderService orderService;

    @Autowired
    WxHomeService wxHomeService;

    @RequestMapping("user/index")
    public BaseRespVo list() {
        Subject subject = SecurityUtils.getSubject();
        MarketUser marketUser = new MarketUser();
        WxIndexVO wxIndexVO = new WxIndexVO();
        if (subject.isAuthenticated()){
            marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
            wxIndexVO = orderService.userIndexList(marketUser.getId());
            return BaseRespVo.ok(wxIndexVO);
        } else {
            return BaseRespVo.noLogin("请登录");
        }

    }

    @RequestMapping("home/index")
    public BaseRespVo homeIndex() {
        WxHomeIndexPageVO homeIndexPageVO = wxHomeService.getHomeIndex();
        return BaseRespVo.ok(homeIndexPageVO);
    }

    @RequestMapping("home/about")
    public BaseRespVo homeAbout() {
        HomeAboutVo homeAboutVo = new HomeAboutVo();
        homeAboutVo.setQq("147258369");
        homeAboutVo.setAddress("无何有境");
        homeAboutVo.setPhone("25222222222");
        homeAboutVo.setLatitude("13.9999");
        homeAboutVo.setName("shana");
        homeAboutVo.setLongitude("11.11");
        return BaseRespVo.ok(homeAboutVo);
    }

}
